home *** CD-ROM | disk | FTP | other *** search
/ Chip: Internet / Chip Internet.iso / viewer / emtex.ins / dvilj4 / findfile.c < prev    next >
C/C++ Source or Header  |  1995-02-17  |  3KB  |  122 lines

  1. #include "config.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. int stat();
  7. char *path_segment();
  8.  
  9. bool
  10. findfile(path,n,fontmag,name)
  11. char path[STRSIZE];  /* PIXEL path */
  12. char n[STRSIZE];     /* name of font */
  13. long fontmag;        /* magnification */
  14. char name[STRSIZE];  /* full name of PXL file  (returned) */
  15. {
  16.     char local_path[STRSIZE];
  17.     char *pathpt;
  18.     struct stat s;
  19.     int rc = -1;
  20.     int resolution, i;
  21.  
  22.     resolution = (int)(fontmag/5.0 +0.5) ;
  23.  
  24.     for(i=0; (pathpt=path_segment((bool)(i==0),path,local_path))!=NULL;i++)
  25.     {
  26. #ifdef USEPXL
  27.         sprintf(name,"%s/%d/%s.pk",pathpt,resolution,n);
  28.         if ((rc = stat(name,&s))!=0)
  29.         {
  30.             sprintf(name,"%s/%d/%s.pxl",pathpt,resolution,n);
  31.             if ((rc = stat(name,&s))!=0)
  32.             {
  33.                 sprintf(name,"%s.pk",n);
  34.                 if ((rc = stat(name,&s))!=0)
  35.                 {
  36.                     sprintf(name,"%s.pxl",n);
  37.                     if ((rc = stat(name,&s))!=0)
  38.                     {
  39.                         sprintf(name,"%s/%ld/%s.pk",pathpt,fontmag,n);
  40.                         if ((rc = stat(name,&s))!=0)
  41.                         {
  42.                             sprintf(name,"%s/%ld/%s.pxl",pathpt,fontmag,n);
  43.                             if ((rc = stat(name,&s))!=0)
  44.                             {
  45. #ifndef MSDOS
  46.                                 sprintf(name,"%s/%d/%s.pk",pathpt,resolution,n);
  47.                                 if ((rc = stat(name,&s))!=0)
  48.                                 {
  49.                                     sprintf(name,"%s/%d/%s.pxl",pathpt,resolution,n);
  50.                                     if ((rc = stat(name,&s))!=0)
  51.                                     {
  52. #endif
  53.                                         sprintf(name,"%s/%d/%s.",pathpt,resolution,n);
  54.                                         rc = stat(name,&s);
  55. #ifndef MSDOS
  56.                                     }
  57.                                 }
  58. #endif
  59.                             }
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.         }
  65. #else
  66.         sprintf(name,"%s/%d/%s.gf",pathpt,resolution,n);
  67.         if ((rc = stat(name,&s))!=0)
  68.         {
  69.             sprintf(name,"%s/%ld/%s.gf",pathpt,fontmag,n);
  70.             rc = stat(name,&s);
  71.         }
  72. #endif
  73.         if (rc==0) return(TRUE);
  74.     };
  75.  
  76. #ifdef FUTURE
  77.     for(i=0; (pathpt=path_segment((bool)(i==0),VFPATH,local_path))!=NULL;i++) {
  78.        sprintf(name,"%s/%s.vfm",pathpt,n);
  79.        printf("searching virtual font <%s>\n",name);
  80.        if (stat(name,&s) == 0) return(TRUE);
  81.     }
  82. #endif
  83.  
  84. #ifdef USEPXL
  85.     /* return error messaage */
  86.     sprintf(name,"font not found: <%s>/<%d;%ld>/%s.gf",
  87.                   path,resolution,fontmag,n);
  88. #else
  89.     sprintf(name,"font not found: <%s>/<%d;%ld>/%s.<pk;pxl>",
  90.                   path,resolution,fontmag,n);
  91. #endif
  92.  
  93. return(FALSE);
  94. }
  95.  
  96. char *
  97. path_segment(first,full_path,local_path)
  98. bool first;
  99. char *full_path, *local_path;
  100. {
  101.     static char *pppt;
  102.     char *pathpt;
  103.  
  104.     if (first) pathpt = strcpy(local_path,full_path);
  105.     else pathpt = pppt;
  106.     if (pathpt != NULL) {
  107. #ifdef unix
  108.                    pppt = strchr(pathpt , ':' );
  109. #else
  110.                 pppt = strchr(pathpt , ';' );
  111. #endif
  112. #ifdef MSDOS
  113.                 pppt = strchr(pathpt , ';' );
  114. #endif
  115.                 if (pppt != NULL) {
  116.                    *pppt = '\0';
  117.                    pppt++;
  118.                    }
  119.         }
  120. return pathpt;
  121. }
  122.